﻿using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Terraria.Achievements
{
	// Token: 0x020004A3 RID: 1187
	[JsonObject(MemberSerialization.OptIn)]
	public abstract class AchievementCondition
	{
		// Token: 0x14000046 RID: 70
		// (add) Token: 0x060027BF RID: 10175 RVA: 0x00495070 File Offset: 0x00493270
		// (remove) Token: 0x060027C0 RID: 10176 RVA: 0x004950A8 File Offset: 0x004932A8
		public event AchievementCondition.AchievementUpdate OnComplete;

		// Token: 0x170002DA RID: 730
		// (get) Token: 0x060027C1 RID: 10177 RVA: 0x0001BDC6 File Offset: 0x00019FC6
		public bool IsCompleted
		{
			get
			{
				return this._isCompleted;
			}
		}

		// Token: 0x060027C2 RID: 10178 RVA: 0x0001BDCE File Offset: 0x00019FCE
		protected AchievementCondition(string name)
		{
			this.Name = name;
		}

		// Token: 0x060027C3 RID: 10179 RVA: 0x0001BDDD File Offset: 0x00019FDD
		public virtual void Load(JObject state)
		{
			this._isCompleted = (bool)state["Completed"];
		}

		// Token: 0x060027C4 RID: 10180 RVA: 0x0001BDF5 File Offset: 0x00019FF5
		public virtual void Clear()
		{
			this._isCompleted = false;
		}

		// Token: 0x060027C5 RID: 10181 RVA: 0x0001BDFE File Offset: 0x00019FFE
		public virtual void Complete()
		{
			if (this._isCompleted)
			{
				return;
			}
			this._isCompleted = true;
			if (this.OnComplete != null)
			{
				this.OnComplete(this);
			}
		}

		// Token: 0x060027C6 RID: 10182 RVA: 0x0000D858 File Offset: 0x0000BA58
		protected virtual IAchievementTracker CreateAchievementTracker()
		{
			return null;
		}

		// Token: 0x060027C7 RID: 10183 RVA: 0x0001BE24 File Offset: 0x0001A024
		public IAchievementTracker GetAchievementTracker()
		{
			if (this._tracker == null)
			{
				this._tracker = this.CreateAchievementTracker();
			}
			return this._tracker;
		}

		// Token: 0x040043EA RID: 17386
		public readonly string Name;

		// Token: 0x040043EB RID: 17387
		protected IAchievementTracker _tracker;

		// Token: 0x040043EC RID: 17388
		[JsonProperty("Completed")]
		private bool _isCompleted;

		// Token: 0x020004A4 RID: 1188
		// (Invoke) Token: 0x060027C9 RID: 10185
		public delegate void AchievementUpdate(AchievementCondition condition);
	}
}
